package com.ltmonitor.video.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 视频请求
 */
@Entity
@Table(name="VideoRequest")
@org.hibernate.annotations.Proxy(lazy = false)
@Inheritance(strategy= InheritanceType.TABLE_PER_CLASS)
public class VideoRequest implements Serializable{

    public static String STATUS_BEGIN = "begin";

    public static String STATUS_END = "end";



    /**
     * 如果userName是政府平台，则表示是政府平台发起的视频请求
     */
    public static String GOVERNMENT_PLATFORM = "government_platform";
    public VideoRequest()
    {
        createDate = new Date();
        startTime = new Date();
        endTime = new Date();
        status = STATUS_BEGIN;
        flow1 = -1;
    }
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "baseId", unique = true, nullable = false)
    private long entityId;

    /**
     * 用户Id
     */
    private long userId;
    /**
     * 用户会话Id
     */
    private String sessionId;

    private String userName;

    private String simNo;

    private String plateNo;

    private int channelId;

    private int streamType;

    /**
     * 音视频数据类型，参见VideoDataType常量类
     */
    private int mediaType;

    private String userIp;

    private Date startTime;

    private String status;

    private Date endTime;

    private Date createDate;

    private double flow1;

    private double flow2;

    private double flow;

    public String getRequestKey()
    {
        StringBuilder sb = new StringBuilder();
        sb.append(simNo).append("_").append(channelId).append("_").append(mediaType).append("_").append(sessionId);
        return sb.toString();
    }

    public long getEntityId() {
        return entityId;
    }

    public void setEntityId(long entityId) {
        this.entityId = entityId;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getSimNo() {
        return simNo;
    }

    public void setSimNo(String simNo) {
        this.simNo = simNo;
    }

    public int getChannelId() {
        return channelId;
    }

    public void setChannelId(int channelId) {
        this.channelId = channelId;
    }

    /**
     * 码流类型
     */
    public int getStreamType() {
        return streamType;
    }

    public void setStreamType(int streamType) {
        this.streamType = streamType;
    }

    /**
     * 音视频数据类型
     */
    public int getMediaType() {
        return mediaType;
    }

    public void setMediaType(int mediaType) {
        this.mediaType = mediaType;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getPlateNo() {
        return plateNo;
    }

    public void setPlateNo(String plateNo) {
        this.plateNo = plateNo;
    }

    public String getUserIp() {
        return userIp;
    }

    public void setUserIp(String userIp) {
        this.userIp = userIp;
    }

    public double getFlow1() {
        return flow1;
    }

    public void setFlow1(double flow1) {
        this.flow1 = flow1;
    }

    public double getFlow2() {
        return flow2;
    }

    public void setFlow2(double flow2) {
        this.flow2 = flow2;
        if(flow1 > flow2)
            flow1 = 0;
        this.flow = flow2 - flow1;
    }


    public double getFlow() {
        return flow;
    }

    public void setFlow(double flow) {
        this.flow = flow;
    }
}
